/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package controller;

import AdminOperations.AdminManageGuest;
import beans.UserType;
import beans.admguestbean;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.actions.DispatchAction;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForward;

/**
 *
 * @author ABDELMOHSEN
 */
public class AdminGuestAction2 extends DispatchAction {
    
    /* forward name="success" path="" */
    private final static String SUCCESS = "success";
    
    public ActionForward lockthread(ActionMapping mapping, ActionForm  form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        
        UserType type=(UserType)request.getSession().getAttribute("type");
        if(type==null||!type.equals(UserType.adm)) return mapping.findForward("login");
        AdminManageGuest model=new AdminManageGuest();
        int id=Integer.parseInt(request.getParameter("id"));
        if(request.getParameter("unlock")==null)
            model.lockThread(id);
        else
            model.unLockThread(id);
        return mapping.findForward("admguest");
    }

    /**
     * This is the Struts action method called on
     * http://.../actionPath?method=myAction2,
     * where "method" is the value specified in <action> element : 
     * ( <action parameter="method" .../> )
     */
    public ActionForward lockreg(ActionMapping mapping, ActionForm  form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        
        UserType type=(UserType)request.getSession().getAttribute("type");
        if(type==null||!type.equals(UserType.adm)) return mapping.findForward("login");
        AdminManageGuest model=new AdminManageGuest();
        admguestbean bean=(admguestbean)form;
        model.lockRegistration(!bean.getReg());
        ServletContext context=getServlet().getServletConfig().getServletContext();
        context.setAttribute("register", String.valueOf(bean.getReg()));
        return mapping.findForward("admguest");
    }
}